﻿#region Using namespaces

using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Markup;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using AvalonDock;
using BOL.Apps.GeneNetworkBrowser.ViewModels;

#endregion

namespace BOL.Apps.GeneNetworkBrowser.Controls
{
    public partial class DocumentViewer : DocumentContent
    {
        public DocumentViewer()
        {
            InitializeComponent();
        }

        public void Load(string fileName)
        {
            using (var fs = new FileStream(fileName, FileMode.Open, FileAccess.Read))
            {
                var content = XamlReader.Load(fs) as FlowDocument;
                DocumentScrollViewer.Document = content;
            }
        }

        public void Save(string fileName)
        {
            using (FileStream fs = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite))
            {
                var document = DocumentScrollViewer.Document;
                var textRange = new TextRange(document.ContentStart, document.ContentEnd);
                textRange.Save(fs, DataFormats.Xaml);
            }
        }
    }
}
